﻿#include "pch.h"

CTsmpBag::CTsmpBag()
{
    memset(this, 0, sizeof(CTsmpBag));
}

void CTsmpBag::printSelf(char *captionUpper, int32_t)
{
    char caption[1024];
    sprintf(caption, "%s:%s", captionUpper, "CTsmpBag");
    print4x(this, sizeof(CTsmpBag), caption);
    if (this->metric)
    {
        sprintf(caption, "%s:%s", captionUpper, "CTsmpBag.metric");
        print4x(this->metric, sizeof(TDLLMETRIC), caption);
    }
    if (this->rawbag)
    {
        sprintf(caption, "%s:%s", captionUpper, "CTsmpBag.rawbag");
        print4x(this->rawbag, sizeof(TRAWBAG), caption);
        if (this->rawbag->head)
        {
            sprintf(caption, "%s:%s", captionUpper, "CTsmpBag.rawbag.head");
            print4x(this->rawbag->head, this->rawbag->len * 4, caption);
        }
        if (this->rawbag->time)
        {
            sprintf(caption, "%s:%s", captionUpper, "CTsmpBag.rawbag.time");
            print4x(this->rawbag->time, sizeof(int32_t), caption);
        }
        if (this->rawbag->freq)
        {
            sprintf(caption, "%s:%s", captionUpper, "CTsmpBag.rawbag.freq");
            print4x(this->rawbag->freq, sizeof(float), caption);
        }
    }
    if (this->Base)
    {
        sprintf(caption, "%s:%s", captionUpper, "CTsmpBag.Base");
        print4x(this->Base, sizeof(int32_t), caption);
    }
}

// sub_1001E6D0
CTsmpBag *CTsmpBag::init(TSMPBAG *smpBag)
{
    this->metric = (TDLLMETRIC *)smpBag->metric;
    this->rawbag = (TRAWBAG *)smpBag->rawbag;
    this->Base = smpBag->Base;
    this->baseMaxTime = smpBag->baseMaxTime;
    return this;
}

// unknown_libname_3
int32_t CTsmpBag::getRawBagLen()
{
    return rawbag->len;
}

// sub_1001B2C0
int32_t CTsmpBag::getRawBagTime()
{
    return *(int32_t *)rawbag->time;
}

// sub_1001B1A0
float *CTsmpBag::getRawBagFreq()
{
    return (float *)rawbag->freq;
}

// sub_1001E70E
int32_t CTsmpBag::getRawBagDrop(int32_t n)
{
    int32_t i;
    int32_t headN = 0;
    if (this->rawbag == NULL)
    {
        return 0;
    }
    if (this->rawbag->head != NULL)
    {
        headN = this->rawbag->head[n];
    }
    if (!this->Base || !this->baseMaxTime)
    {
        return headN;
    }
    if (n >= this->baseMaxTime)
    {
        i = this->baseMaxTime - 1;
    }
    else
    {
        i = n;
    }
    return headN - (this->Base[i] - this->Base[0]);
}

// sub_1001B730
float CTsmpBag::getRawBagFreqValue()
{
    return *(float *)rawbag->freq;
}
